package com.icode.core.model.house;

import com.icode.core.dto.house.HouseWeekDTO;
import com.icode.core.model.AbstractEntity;

import javax.persistence.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sunk
 * Date: 15-1-9
 * Time: 下午4:29
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "house_week")
public class HouseWeek extends AbstractEntity {
    @Column
    private String name;
    private String description;
    @Column
    private String price;
    @Column(name = "house_base_area")
    @Enumerated(EnumType.STRING)
    private HouseBaseArea houseBaseArea;
    @ManyToOne
    @JoinColumn(name = "house_info_id")
    private HouseInfo houseInfo;
    @Column(name = "total_num")
    private int totalNum;
    @Column(name = "sold_num")
    private int soldNum;

    @Column(name = "week_reg")
    private String weekReg;
    @Column(name = "min_date")
    private String minDate;
    @Column(name = "max_date")
    private String maxDate;

    @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
    @JoinColumn(name = "house_week_id")
    private List<HouseWeekTime> houseWeekTimes;

    public HouseWeek() {
    }

    public HouseWeek(String name, String price, HouseBaseArea houseBaseArea, HouseInfo houseInfo, String weekReg, String minDate, String maxDate) {
        this.name = name;
        this.price = price;
        this.houseBaseArea = houseBaseArea;
        this.houseInfo = houseInfo;
        this.weekReg = weekReg;
        this.minDate = minDate;
        this.maxDate = maxDate;
    }

    public HouseWeek(String name, String description, String price, HouseBaseArea houseBaseArea, HouseInfo houseInfo) {
        this.name = name;
        this.description = description;
        this.price = price;
        this.houseBaseArea = houseBaseArea;
        this.houseInfo = houseInfo;
    }

    public HouseWeek(HouseInfo houseInfo, String week, String price, String description, String totalNum,HouseBaseArea houseBaseArea) {
        this.name = week;
        this.description = description;
        this.houseInfo=houseInfo;
        this.price = price;
        this.totalNum=Integer.valueOf(totalNum);
        this.houseBaseArea = houseBaseArea;
    }

    public void initHouseWeek(String name, String price, HouseBaseArea houseBaseArea, HouseInfo houseInfo) {
        this.name = name;
        this.price = price;
        this.houseBaseArea = houseBaseArea;
        this.houseInfo = houseInfo;
    }

    public void initHouseWeekTime(List<HouseWeekTime> houseWeekTimes) {
        this.houseWeekTimes = houseWeekTimes;
    }

    public String name() {
        return name;
    }

    public String description() {
        return description;
    }

    public String price() {
        return price;
    }

    public HouseBaseArea houseBaseArea() {
        return houseBaseArea;
    }

    public HouseInfo houseInfo() {
        return houseInfo;
    }

    public List<HouseWeekTime> houseWeekTimes() {
        return houseWeekTimes;
    }

    public void setHouseWeekTimes(List<HouseWeekTime> houseWeekTimes) {
        this.houseWeekTimes = houseWeekTimes;
    }

    public String weekReg() {
        return weekReg;
    }

    public String minDate() {
        return minDate;
    }

    public void setWeekReg(String weekReg) {
        this.weekReg = weekReg;
    }

    public String maxDate() {
        return maxDate;
    }

    public int totalNum() {
        return totalNum;
    }

    public int soldNum() {
        return soldNum;
    }

    public void setSoldNum(int soldNum) {
        this.soldNum = soldNum;
    }

    public void upDateBase(HouseWeekDTO houseWeekDTO){
        this.description=houseWeekDTO.getDescription();
        this.price = houseWeekDTO.getPrice();
        this.totalNum = houseWeekDTO.getTotalNum();
    }

    public void upDateBase(String price, String description, String totalNum) {
        this.description=description;
        this.price = price;
        this.totalNum =  Integer.valueOf(totalNum);
    }
}
